<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------

/**
 * Class InvoiceTitle
 * Desc  抬头校验
 * Create on 2024/10/11 11:19
 * Create by wangyafang
 */
namespace app\api\validate\wddj;

use think\Validate;

class InvoiceTitle extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'invoice_type'=>'require|checkInvoiceType',
        'invoice_title'=>'require',
        'mobile'=>'require|checkMobile',
        'email'=>'require|checkEmail',

    ];
    /**
     * 提示消息
     */
    protected $message = [
        'invoice_type.require'=>'请选择发票类型',
        'invoice_title.require'=>'请输入发票抬头',
        'mobile.require'=>'请输入联系电话',
        'email.require'=>'请输入电子邮箱',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'create'  => [
            'name',
            'mobile',
            'emergency_contact_mobile',
            'subject_matter_price',
            'subject_matter_link',
            'province',
            'city',
            'branch_id',
            'order_taking_method',
            'pay_method'
        ],
    ];

    protected function checkMobile($value,$rule,$data)
    {
        if (!$value || !\think\Validate::regex($value, "^1\d{10}$")) {
            return '手机号格式不正确';
        }
        return true;
    }

    protected function checkEmail($value,$rule,$data)
    {
        if (!\think\Validate::is($value, 'email')) {
            return '邮箱格式不正确';
        }
        return true;
    }

    protected function checkInvoiceType($value,$rule,$data)
    {
        if ($value == 1 && empty($data['title_type'])) {
            return '请选择抬头类型';
        }
        if (($value == 1 && $data['title_type'] == 2) || ($value == 2)) {
            if (empty($data['unit_tax_number'])) {
                return '请输入单位税号';
            }
            if (empty($data['registered_address'])) {
                return '请输入单位注册地址';
            }
            if (empty($data['bank_of_deposit'])) {
                return '请输入开户银行';
            }
            if (empty($data['bank_no'])) {
                return '请输入银行行号';
            }
        }
        return true;
    }




}



 